package cn.xiaoniu.day03.utils;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;

import ch.hsr.geohash.GeoHash;

public class Utils {
	/**
	 * 把二维的经纬度信息转化为一维的数据
	 * @param localy
	 * @param localx
	 * @return
	 */
	public static String getGeoHash(double localy,double localx){
		String base32 = GeoHash.withCharacterPrecision(localy, localx, 8).toBase32();
		return base32;
	}
	
	/**
	 * 通过经纬度信息，去获取位置信息数据（返回json数据）
	 */
	public static String getJsonByNet(double lat,double lng){
		HttpClient client = new HttpClient();
		String uri = "http://gc.ditu.aliyun.com/regeocoding?l=" + lat + "," + lng+"&type=010";
		HttpMethod method = new GetMethod(uri);
		try {
			client.executeMethod(method);
			String ret = method.getResponseBodyAsString();
			return ret;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
	}
	
	

}
